package cn.easybuy.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.easybuy.biz.Easybuy_UserBiz;
import cn.easybuy.biz.Impl.Easybuy_UserBizImpl;
import cn.easybuy.entity.Easybuy_User;

public class Easybuy_Login extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		String name = request.getParameter("name");
		String password = request.getParameter("password");
		Easybuy_User easybuy_User = new Easybuy_User();
		Easybuy_UserBiz easybuy_UserBiz = new Easybuy_UserBizImpl();
		easybuy_User = easybuy_UserBiz.getUserPassword(name, password);
		if (easybuy_User != null) {
			HttpSession session = request.getSession();
			session.setAttribute("easybuy_User", easybuy_User);
			request.getRequestDispatcher("../Index1.jsp").forward(request,
					response);
		} else {
			request.getRequestDispatcher("../Login.jsp").forward(request,
					response);
		}

	}

}
